
*******************************************************************************************************************
*This do file runs the results presented in "The Effect of Subsidized Flood Insurance on Real Estate Markets"** 
*******************************************************************************************************************

use  data_JRI.dta,clear

keep if year>2011

**MERGE continuous flood event measures**

drop _merge_B
merge m:1 plc using "flood_event_new_final_RE.dta", generate(_merge_B)
drop if _merge_B==2
drop _merge_B
forvalues xx==1(1)23{
gen gap_flood_`xx'=date2-date_start_`xx'
replace gap_flood_`xx'=. if gap_flood_`xx'<0
gen negagap_flood_`xx'=date2-date_start_`xx'
replace negagap_flood_`xx'=. if negagap_flood_`xx'>0
}
egen mingap=rowmin (gap_flood_1 gap_flood_1 gap_flood_2 gap_flood_3 gap_flood_4 gap_flood_5 gap_flood_6 gap_flood_7 gap_flood_8 gap_flood_9 gap_flood_10 gap_flood_11 gap_flood_12 gap_flood_13 gap_flood_14 gap_flood_15 gap_flood_16 gap_flood_17 gap_flood_18 gap_flood_19 gap_flood_20 gap_flood_21 gap_flood_22 gap_flood_23)

egen maxnegagap=rowmax (negagap_flood_1 negagap_flood_2 negagap_flood_3 negagap_flood_4 negagap_flood_5 negagap_flood_6 negagap_flood_7 negagap_flood_8 negagap_flood_9 negagap_flood_10 negagap_flood_11 negagap_flood_12 negagap_flood_13 negagap_flood_14 negagap_flood_15 negagap_flood_17 negagap_flood_18 negagap_flood_19 negagap_flood_20 negagap_flood_21 negagap_flood_22 negagap_flood_23)

gen temp=1 if flooded==1 | f_flooded==1

gen l_start=.
forvalues xx==1(1)23{
replace l_start=date_start_`xx' if mingap==gap_flood_`xx' & temp==1
}
gen l_gap=date2-l_start

forvalues xx==1(1)23{
replace duration_`xx' =. if gap_flood_`xx'>1460
}
egen maxdur=rowmax (duration_1 duration_2 duration_3 duration_4 duration_5 duration_6 duration_7 duration_8 duration_9 duration_10 duration_11 duration_12 duration_13 duration_14 duration_15 duration_16 duration_17 duration_18 duration_19 duration_20 duration_21 duration_22 duration_23)

sum maxdur if flooded==1
sum maxdur if f_flooded==1

winsor2 maxdur,cut(1 99) replace
replace  maxdur=0 if maxdur==.
replace maxdur=maxdur/100
gen f_re_maxdur=f_re*maxdur
drop if  nuts118nm=="Wales"

*****************************************
reghdfe d_price flooded   f_re_f f_flooded  f_re_ff  if year>2011 ,absorb(lag_new v5 v6 build_year plc3_group ) cluster(LA_ID)
gen sample=e(sample)
*****************************************
**Flood duration**
*************************************

reghdfe d_price maxdur if sample==1 & year>2011 ,absorb(lag_new v5 v7 build_year plc3dig_minyear plc3dig_maxyear ) cluster(LA_ID)
outreg2 using "Result_T3panelb.xls", label tstat bdec(3) tdec(2)

reghdfe d_price maxdur f_re_maxdur if sample==1 & year>2011 ,absorb(lag_new v5 v7 build_year plc3dig_minyear plc3dig_maxyear ) cluster(LA_ID)
outreg2 using "Result_T3panelb.xls", label tstat bdec(3) tdec(2)

reghdfe d_price maxdur f_re_maxdur if sample==1 & year>2011 ,absorb(lag_new v5 v7 build_year plc3_group ) cluster(LA_ID)
outreg2 using "Result_T3panelb.xls", label tstat bdec(3) tdec(2)

gen reverse_plc=reverse(plc)
gen last3_plc=substr(reverse_plc,1,3)
gen first3_plc=substr(reverse_plc,4,7)
replace last3_plc=reverse(last3_plc)
replace first3_plc=reverse(first3_plc)
replace plc=first3_plc+" "+last3_plc

drop _merge
merge m:1 plc using "Overall_SW_2016.dta"
drop if _merge==2
drop _merge

foreach xx of var residential_risk_verylow residential_risk_low residential_risk_medium residential_risk_high{
replace `xx'=0 if `xx'==.
}
gen 			flood_risk_midpoint 	= (0.05*residential_risk_verylow+0.55*residential_risk_low+2.15*residential_risk_medium+5*residential_risk_high)/(residential_risk_verylow+residential_risk_low+residential_risk_medium+residential_risk_high)
replace 		flood_risk_midpoint 	= 0		if (residential_risk_verylow+residential_risk_low+residential_risk_medium+residential_risk_high)==0
gen 			properties_classified = (residential_risk_verylow+residential_risk_low+residential_risk_medium+residential_risk_high) 

gen risk_cat="v_low" if flood_risk_midpoint<0.1
replace risk_cat="low" if flood_risk_midpoint>=0.1 & flood_risk_midpoint<1
replace risk_cat="medium" if flood_risk_midpoint>=1 & flood_risk_midpoint<3.3
replace risk_cat="high" if flood_risk_midpoint>=3.3 

gen h_risk=1 if risk_cat=="high" | risk_cat=="medium" | risk_cat=="low"
replace h_risk=0 if h_risk==.
foreach pp of var no_po sop f_map f_re {
gen `pp'_h_risk=`pp'*h_risk
}
gen f_re__flood_risk_midpoint=f_re*flood_risk_midpoint
*****************************************
****Flood risk midpoint***
*************************************
reghdfe d_price    flood_risk_midpoint if sample==1 & year>2011 ,absorb(lag_new v5 v7 build_year plc3_group ) cluster(LA_ID)
outreg2 using "Result_T3panelb.xls", label tstat bdec(3) tdec(2)

reghdfe d_price  flood_risk_midpoint f_re__flood_risk_midpoint if sample==1 & year>2011,absorb(lag_new v5 v7 build_year plc3dig_minyear plc3dig_maxyear ) cluster(LA_ID)
outreg2 using "Result_T3panelb.xls", label tstat bdec(3) tdec(2)

reghdfe d_price    flood_risk_midpoint f_re__flood_risk_midpoint if sample==1 & year>2011 ,absorb(lag_new v5 v7 build_year plc3_group ) cluster(LA_ID)
outreg2 using "Result_T3panelb.xls", label tstat bdec(3) tdec(2)

**************************************
**************************************
use "data_JRI.dta",clear

***define sample******
reghdfe d_price flooded f_flooded if year>2011  ,absorb(lag_new v5 v7 build_year plc3_group ) cluster(LA_ID)
gen sample=e(sample)


****Table 3*****
reghdfe d_price flooded f_flooded if year>2011 & sample==1 ,absorb( build_year plc3dig_minyear plc3dig_maxyear ) cluster(LA_ID)
outreg2 using "Result_T3.xls",  label tstat bdec(3) tdec(2)

reghdfe d_price flooded   f_re_f f_flooded  f_re_ff if year>2011 & sample==1,absorb(lag_new v5 v7 build_year plc3dig_minyear plc3dig_maxyear ) cluster(LA_ID)
outreg2 using "Result_T3.xls", label tstat bdec(3) tdec(2)

reghdfe d_price flooded   f_re_f f_flooded  f_re_ff  if year>2011 & sample==1,absorb(lag_new v5 v7 build_year plc3_group ) cluster(LA_ID)
outreg2 using "Result_T3.xls", label tstat bdec(3) tdec(2)

****Table 4***
gen placebo=1 if date2>=td(1jul2013) & date2<=td(4apr2016)
replace placebo=0 if placebo==.
gen p_f=placebo*flooded
gen p_ff=placebo*f_flooded
reghdfe d_price flooded  p_f f_flooded   p_ff if date2>=td(4apr2010) & date2<=td(4apr2016),absorb(build_year plc3_group ) cluster(LA_ID)
gen p_sample=e(sample)

reghdfe d_price flooded  p_f f_flooded   p_ff if p_sample==1 &  date2>=td(4apr2010) & date2<=td(4apr2016) ,absorb(lag_new v5 v7 build_year plc3dig_minyear plc3dig_maxyear ) cluster(LA_ID)
outreg2 using "Result_T4.xls", label tstat bdec(3) tdec(2) 

reghdfe d_price flooded  p_f f_flooded   p_ff if p_sample==1 &  date2>=td(4apr2010) & date2<=td(4apr2016),absorb(lag_new v5 v7 build_year plc3_group ) cluster(LA_ID)
outreg2 using "Result_T4.xls", label tstat bdec(3) tdec(2) 
******panel B*****
/*
preserve
drop if flooded==1 | f_flooded==1
drop flooded f_re_f
keep if sample==1
forvalues i = 1/1000 {
randomselect  , gen(flooded)  n(6000)
gen f_re_f=f_re*flooded
reghdfe d_price flooded   f_re_f  ,absorb(lag_new v5 v7 build_year plc3_group ) cluster(LA_ID)
outreg2 using "Result_T4_placebo_nowales.xls", label tstat bdec(3) tdec(2)
drop flooded   f_re_f
}
restore
*/
***********************************************
***********Table 6*****************************
keep if sample==1
preserve
bysort LA_ID:drop if _n>1
tabstat mean_income AverageScore H Medianage avg_green_share Pct_Leave, stat(N mean p25 p50 p75)
restore

****income***Income estimates for small areas, England and Wales
gen abv_income=1 if mean_income>=40565.11  & mean_income!=.
replace abv_income=0 if abv_income==. & mean_income!=.

reghdfe d_price flooded   f_re_f f_flooded  f_re_ff  if  abv_income==1 & year>2011 & sample==1,absorb(lag_new v5 v7 build_year plc3_group ) cluster(LA_ID)
outreg2 using "Result_T6.xls", label tstat bdec(3) tdec(2)

reghdfe d_price flooded   f_re_f f_flooded  f_re_ff  if  abv_income==0 & year>2011 & sample==1,absorb(lag_new v5 v7 build_year plc3_group ) cluster(LA_ID)
outreg2 using "Result_T6.xls", label tstat bdec(3) tdec(2)


****deprivation***
gen abv_dep=1 if AverageScore>=18.6 & AverageScore!=.
replace abv_dep=0 if abv_dep==. & AverageScore!=.

reghdfe d_price flooded   f_re_f f_flooded  f_re_ff  if abv_dep==1 & year>2011 & sample==1,absorb(lag_new v5 v7 build_year plc3_group ) cluster(LA_ID)
outreg2 using "Result_T6.xls", label tstat bdec(3) tdec(2)

reghdfe d_price flooded   f_re_f f_flooded  f_re_ff  if abv_dep==0 & year>2011 & sample==1,absorb(lag_new v5 v7 build_year plc3_group ) cluster(LA_ID)
outreg2 using "Result_T6.xls", label tstat bdec(3) tdec(2)

***age**
gen abv_age=1 if Medianage>=42.25 & Medianage!=.
replace abv_age=0 if abv_age==. & Medianage!=.

reghdfe d_price flooded   f_re_f f_flooded  f_re_ff  if abv_age==1 & year>2011 & sample==1,absorb(lag_new v5 v7 build_year plc3_group ) cluster(LA_ID)
outreg2 using "Result_T6.xls", label tstat bdec(3) tdec(2)

reghdfe d_price flooded   f_re_f f_flooded  f_re_ff  if abv_age==0 & year>2011 & sample==1,absorb(lag_new v5 v7 build_year plc3_group ) cluster(LA_ID)
outreg2 using "Result_T6.xls", label tstat bdec(3) tdec(2)

****Education***
gen abv_edu=1 if H>=25.95 & H!=.
replace abv_edu=0 if abv_edu==. & H!=.

reghdfe d_price flooded   f_re_f f_flooded  f_re_ff  if abv_edu==1 & year>2011 & sample==1,absorb(lag_new v5 v7 build_year plc3_group ) cluster(LA_ID)
outreg2 using "Result_T6.xls", label tstat bdec(3) tdec(2)

reghdfe d_price flooded   f_re_f f_flooded  f_re_ff  if abv_edu==0 & year>2011 & sample==1,absorb(lag_new v5 v7 build_year plc3_group ) cluster(LA_ID)
outreg2 using "Result_T6.xls", label tstat bdec(3) tdec(2)


**Urban-rural**
gen urban=1 if ruc11cd>=3
replace urban=0 if ruc11cd<3
tab flooded if urban==1
tab flooded if urban==0
reghdfe d_price flooded   f_re_f f_flooded  f_re_ff  if  urban==1 & year>2011 & sample==1,absorb(lag_new v5 v7 build_year plc3_group ) cluster(LA_ID)
outreg2 using "Result_T6.xls", label tstat bdec(3) tdec(2)

reghdfe d_price flooded   f_re_f f_flooded  f_re_ff  if  urban==0 & year>2011 & sample==1,absorb(lag_new v5 v7 build_year plc3_group ) cluster(LA_ID)
outreg2 using "Result_T6.xls", label tstat bdec(3) tdec(2)

***Sample split - rent rate***

preserve
bysort LA_ID:drop if _n>1
tabstat rent_rate, stat(N mean p25 p50 p75)
restore
drop _merge

*******
gen abv_rent=1 if rent_rate>=32.28  & rent_rate!=.
replace abv_rent=0 if abv_rent==. & rent_rate!=.
sum  rent_rate
reghdfe d_price flooded   f_re_f f_flooded  f_re_ff  if  abv_rent==1 & year>2011 & sample==1,absorb(lag_new v5 v7 build_year plc3_group ) cluster(LA_ID)
outreg2 using "Result_T6.xls", label tstat bdec(3) tdec(2)

reghdfe d_price flooded   f_re_f f_flooded  f_re_ff  if  abv_rent==0 & year>2011 & sample==1,absorb(lag_new v5 v7 build_year plc3_group ) cluster(LA_ID)
outreg2 using "Result_T6.xls", label tstat bdec(3) tdec(2)


***Table 6***
****grenn party ***
gen green=1 if avg_green_share>=2.76
replace green=0 if avg_green_share<2.76

reghdfe d_price flooded   f_re_f f_flooded  f_re_ff  if  green==1 & year>2011 & sample==1,absorb(lag_new v5 v7 build_year plc3_group ) cluster(LA_ID)
outreg2 using "Result_T7.xls", label tstat bdec(3) tdec(2)

reghdfe d_price flooded   f_re_f f_flooded  f_re_ff  if  green==0 & year>2011 & sample==1,absorb(lag_new v5 v7 build_year plc3_group ) cluster(LA_ID)
outreg2 using "Result_T7.xls", label tstat bdec(3) tdec(2)

****brexit***
gen leave=1 if Pct_Leave>=55.46
replace leave=0 if leave==.

reghdfe d_price flooded   f_re_f f_flooded  f_re_ff  if  leave==1 & year>2011 & sample==1,absorb(lag_new v5 v7 build_year plc3_group ) cluster(LA_ID)
outreg2 using "Result_T7.xls", label tstat bdec(3) tdec(2) 

reghdfe d_price flooded   f_re_f f_flooded  f_re_ff  if  leave==0 & year>2011 & sample==1,absorb(lag_new v5 v7 build_year plc3_group ) cluster(LA_ID)
outreg2 using "Result_T7.xls", label tstat bdec(3) tdec(2)



 *************Ex-ante risk measure*********
gen reverse_plc=reverse(plc)
gen last3_plc=substr(reverse_plc,1,3)
gen first3_plc=substr(reverse_plc,4,7)
replace last3_plc=reverse(last3_plc)
replace first3_plc=reverse(first3_plc)
replace plc=first3_plc+" "+last3_plc
merge m:1 plc using "Overall_SW_2016.dta"


drop if _merge==2
drop _merge
foreach xx of var residential_risk_verylow residential_risk_low residential_risk_medium residential_risk_high{
replace `xx'=0 if `xx'==.
}
gen 			flood_risk_midpoint 	= (0.05*residential_risk_verylow+0.55*residential_risk_low+2.15*residential_risk_medium+5*residential_risk_high)/(residential_risk_verylow+residential_risk_low+residential_risk_medium+residential_risk_high)
replace 		flood_risk_midpoint 	= 0		if (residential_risk_verylow+residential_risk_low+residential_risk_medium+residential_risk_high)==0
gen 			properties_classified = (residential_risk_verylow+residential_risk_low+residential_risk_medium+residential_risk_high) 

gen risk_cat="v_low" if flood_risk_midpoint<0.1
replace risk_cat="low" if flood_risk_midpoint>=0.1 & flood_risk_midpoint<1
replace risk_cat="medium" if flood_risk_midpoint>=1 & flood_risk_midpoint<3.3
replace risk_cat="high" if flood_risk_midpoint>=3.3 

gen h_risk=1 if risk_cat=="high" | risk_cat=="medium" | risk_cat=="low" 
replace h_risk=0 if h_risk==.
gen f_re_h_risk=f_re*h_risk


*************************************
reghdfe d_price  h_risk if year>2011 & sample==1 ,absorb( build_year plc3dig_minyear plc3dig_maxyear ) cluster(LA_ID)
outreg2 using "Result_T3.xls",  label tstat bdec(3) tdec(2)


reghdfe d_price   h_risk f_re_h_risk  if year>2011 & sample==1 ,absorb(lag_new v5 v7 build_year plc3dig_minyear plc3dig_maxyear ) cluster(LA_ID)
outreg2 using "Result_T3.xls", label tstat bdec(3) tdec(2)


reghdfe d_price   h_risk f_re_h_risk  if year>2011 & sample==1,absorb(lag_new v5 v7 build_year plc3_group ) cluster(LA_ID)
outreg2 using "Result_T3.xls", label tstat bdec(3) tdec(2)
*********************************************

***Table 9***

reghdfe d_price flooded   f_re_f f_flooded  f_re_ff  if h_risk ==1 & year>2011 & sample==1,absorb(lag_new v5 v7 build_year plc3_group ) cluster(LA_ID)
outreg2 using "Result_T9.xls", label tstat bdec(3) tdec(2)


reghdfe d_price flooded   f_re_f f_flooded  f_re_ff  if h_risk ==0 & year>2011 & sample==1,absorb(lag_new v5 v7 build_year plc3_group ) cluster(LA_ID)
outreg2 using "Result_T9.xls", label tstat bdec(3) tdec(2)


****Table 5****
encode v5 , generate(prop_type)
encode v7 , generate(duration)
xi:reghdfe d_price flooded   f_re_f f_flooded  f_re_ff prop_type##flooded prop_type##f_flooded duration##flooded duration##f_flooded  lag_new##flooded lag_new##f_flooded build_year##flooded build_year##f_flooded  if year>2011  & sample==1  ,absorb(plc3_group ) cluster(LA_ID)
outreg2 using "Result_T5.xls", label tstat bdec(3) tdec(2)


reghdfe d_price  flooded   f_re_f f_flooded  f_re_ff  h_risk f_re_h_risk  if year>2011 & sample==1,absorb(lag_new v5 v7 build_year plc3_group ) cluster(LA_ID)
outreg2 using "Result_T5.xls", label tstat bdec(3) tdec(2)


bys plc3_group : egen sum_f=sum(flooded)
bys plc3_group : egen sum_ff=sum(f_flooded)
gen totalf=1 if sum_f>0 | sum_ff>0
*****************************************************
**At least one property flooded***
reghdfe d_price flooded   f_re_f f_flooded  f_re_ff  if year>2011 & sample==1 & totalf==1 ,absorb(lag_new v5 v7 build_year plc3_group ) cluster(LA_ID)
outreg2 using "Result_T5.xls", label tstat bdec(3) tdec(2)

**No Flat***
reghdfe d_price flooded   f_re_f f_flooded  f_re_ff  if year>2011  & sample==1  & v5!="F",absorb(lag_new v5 v7 build_year plc3dig_minyear plc3dig_maxyear ) cluster(LA_ID)
gen samplea=e(sample)
reghdfe d_price flooded   f_re_f f_flooded  f_re_ff if year>2011 & sample==1  & v5!="F",absorb( build_year plc3_group ) cluster(LA_ID)
gen sampleb=e(sample)
*ln_price d_price lag_new v5 v6  flooded f_flooded f_re_f f_re_ff h_risk
reghdfe d_price flooded   f_re_f f_flooded  f_re_ff if samplea==1 & sampleb==1,absorb(lag_new v5 v7 build_year plc3_group ) cluster(LA_ID)
outreg2 using "Result_T5.xls", label tstat bdec(3) tdec(2)
drop samplea sampleb

**Figure 2**
**price in first trade
gen first_price=ln_price-d_price
xtile quant=first_price, n(5)
bys quant:sum first_price

forvalues xx=1(1)5{
reghdfe d_price flooded   f_re_f f_flooded  f_re_ff  if year>2011 & sample==1 & quant==`xx',absorb(lag_new v5 v7 build_year plc3_group ) cluster(LA_ID)
estimates store pp`xx'D
}

coefplot  (pp1D,asequation(p20)) (pp2D,asequation(p40)) (pp3D,asequation(p60)) (pp4D,asequation(p80)) (pp5D,asequation(p100)),xtitle("Perctile of house price in the first trade") ytitle("Estimated coefficient of Flooded X Post Flood Re") vertical keep(f_re_f) levels(90) nolabel eqstrict yline(0) legend(off)
************************
***Table 1****
xi:reg d_price i.v5 i.v7 
gen _Iv5_1=1 if v5=="D"
replace _Iv5_1=0 if v5!="D"

gen _Iv7_1=1 if v7=="F"
replace _Iv7_1=0 if v7!="F"

tabstat ln_price d_price   lag_new _Iv5_1 _Iv5_4 _Iv5_5 _Iv5_2 _Iv5_3 _Iv7_1 _Iv7_2 flooded f_flooded h_risk  if sample==1,stat(N mean sd p5 p95 min max)columns(statistics) save
mat T=r(StatTotal)
putexcel set "ss-property level.xlsx",replace
putexcel A1 = matrix(T), names

preserve
bysort LA_ID:drop if _n>1
tabstat  mean_income AverageScore Medianage urban H rent_rate avg_green_share   Pct_Leave  if sample==1, stat(N mean sd p5 p95 min max)columns(statistics) save
mat T=r(StatTotal)
putexcel set "ss-LA level.xlsx",replace
putexcel A1 = matrix(T), names
restore

*******Table 2*****
label var _Iv5_1  "Detached"
label var _Iv5_2 "Flat"
label var _Iv5_3 "Other"
label var _Iv5_4 "Semi-Detached"
label var _Iv5_5 "Terraced"
label var _Iv7_1 "Freehold"
label var _Iv7_2 "Leasehold"
label var lag_new "New" 

label var H "Education-level" 
label var AverageScore "Index-of-multiple-deprivation " 
label var mean_income "Annual-household-income" 
label var rent_rate "Rental-rate" 
label var Pct_Leave "Vote-for-Brexit" 
label var avg_green_share "Vote-for-the-Green-Party"
label var Medianage "Age" 
label var urban "Urban"

local des     _Iv5_1 _Iv5_4  _Iv5_5 _Iv5_2 _Iv5_3  _Iv7_1 _Iv7_2  lag_new mean_income AverageScore Medianage urban H rent_rate avg_green_share   Pct_Leave 
*mat ttest=J(`: word count `des'',5,.)
mat ttest=J(20,5,.)
local j 0
foreach x in `des'{
local ++j
qui: sum `x' if flooded==1, d
mat ttest[`j',1]=`r(mean)'
scalar a1=`r(mean)'
mat ttest[`j',2]=`r(sd)'
scalar a2=`r(sd)'
qui: sum `x' if flooded==0, d
mat ttest[`j',3]=`r(mean)'
scalar a3=`r(mean)'
mat ttest[`j',4]=`r(sd)'
scalar a4=`r(sd)'
mat ttest[`j',5]=(a1-a3)/sqrt(a2^2+a4^2)
local name `"`: var label `x' '"'
local name2 `name2' `name'
}

mat colnames ttest="Mean" "SD" "Mean" "SD" "ND"  
*"N" "Mean" "SD" "1st" "99th"
mat rownames ttest=`name2'
outtable using "T2_pair_panel_A", mat(ttest) replace format(%9.3f %9.3f %9.3f %9.3f %9.3f) nobox

local des  _Iv5_1 _Iv5_4  _Iv5_5 _Iv5_2 _Iv5_3  _Iv7_1 _Iv7_2  lag_new mean_income AverageScore Medianage urban H rent_rate avg_green_share   Pct_Leave 
*mat ttest=J(`: word count `des'',5,.)
mat ttest=J(20,5,.)
local j 0
foreach x in `des'{
local ++j
qui: sum `x' if h_risk==1, d
mat ttest[`j',1]=`r(mean)'
scalar a1=`r(mean)'
mat ttest[`j',2]=`r(sd)'
scalar a2=`r(sd)'
qui: sum `x' if h_risk==0, d
mat ttest[`j',3]=`r(mean)'
scalar a3=`r(mean)'
mat ttest[`j',4]=`r(sd)'
scalar a4=`r(sd)'
mat ttest[`j',5]=(a1-a3)/sqrt(a2^2+a4^2)
local name `"`: var label `x' '"'
local name2 `name2' `name'
}
mat colnames ttest="Mean" "SD" "Mean" "SD" "ND"  
*"N" "Mean" "SD" "1st" "99th"
mat rownames ttest=`name2'
outtable using "T2_pair_panel_b", mat(ttest) replace format(%9.3f %9.3f %9.3f %9.3f %9.3f) nobox

********************************************************
********************************************************



***Table 8 and 9***
use balanced_panel_sample.dta,clear

***Table 8 and 9***
reghdfe  trade flooded   f_re_f f_flooded  f_re_ff   if sample==1 &  year>2011 ,absorb( v5 v7 build_year plc3dig_period) cluster(LA_ID)
outreg2 using "Result_T8.xls", label tstat bdec(3) tdec(2)
preserve
***Flooded (Flash-flooded)=1 if there is at least one flooding (flash-flooding) between the current and previous transaction.**** 
use day_since_lasttrade.dta,clear
reghdfe ln_t_gap flooded   f_re_f f_flooded  f_re_ff if sample==1 & year>2011 ,absorb(lag_new v5 v7 build_year plc3dig_minyear plc3dig_maxyear)cluster(LA_ID)
outreg2 using "Result_T8.xls", label tstat bdec(3) tdec(2)
restore
reghdfe  trade flooded flooded   f_re_f f_flooded  f_re_ff   if sample==1   & h_risk==1 & year>2011 ,absorb( v5 v7 build_year plc3dig_period) cluster(LA_ID)
outreg2 using "Result_T9.xls", label tstat bdec(3) tdec(2)
reghdfe  trade flooded flooded   f_re_f f_flooded  f_re_ff   if sample==1 & h_risk==0 &  year>2011 ,absorb( v5 v7 build_year plc3dig_period) cluster(LA_ID)
outreg2 using "Result_T9.xls", label tstat bdec(3) tdec(2)

*****Table 10**
use property_built_after2002.dta,clear

***Table 10**
reghdfe d_price flooded   f_re_f f_flooded  f_re_ff  if year>2011 ,absorb(lag_new v5 v7 build_year plc3_group ) cluster(LA_ID)
outreg2 using "Result_T10.xls", label tstat bdec(3) tdec(2)
keep if e(sample)==1
reghdfe d_price flooded   f_re_f f_flooded  f_re_ff  if year>2011 & build_year>2008,absorb(lag_new v5 v7 build_year plc3_group ) cluster(LA_ID)
outreg2 using "Result_T10.xls", label tstat bdec(3) tdec(2)
